//
// Add the event listener.
// This has to be on keydown or keyup because webkit doesn't
// generate keypress events for nonprintable keys.
if (document.addEventListener) {		// DOM way
  //document.addEventListener("keypress", onKeyPress, false);
  document.addEventListener("keyup", onKeyPress, false);
}
else if (document.all)			// IE way
  document.attachEvent("onkeypress", onKeyPress);

//
// Keypress navigation
function onKeyPress(e)
{
  // IE doesn't see the event argument passed in, so get it this way:
  if (window.event) e = window.event;

  alert("key press, char code " + e.charCode + ", key code " + e.keyCode );

  return;

  // Mozilla uses charCode for printable characters, keyCode for unprintables:
  if (e.charCode) {
    switch (e.charCode) {
      case 32:
        nextSlide();
        e.preventDefault();
        return;
      // The Logitech Presenter sends a period from the "blank screen" btn
      case 46:
        blankScreen();
        e.preventDefault();
        return;
    }
  }

  if (e.shiftKey == 1) {
    switch (e.keyCode) {
      case 33:    // e.DOM_VK_PAGE_UP:
      case 33:    // e.DOM_VK_PAGE_UP:
        tableOfContents();
        e.preventDefault();
        return;
    }
    return;
  }
  if (e.ctrlKey == 1 || e.altKey == 1) {
    return;
  }

  // Use numeric values rather than DOM_VK_* so that non-mozilla browsers
  // might work.
  switch (e.keyCode) {
    case 32:    // e.DOM_VK_SPACE:
    case 34:    // e.DOM_VK_PAGE_DOWN:
    case 39:    // e.DOM_VK_RIGHT:
      nextSlide();
      e.preventDefault();
      return;
    case 8:     // e.DOM_VK_BACK_SPACE:
    case 33:    // e.DOM_VK_PAGE_UP:
    case 37:    // e.DOM_VK_LEFT:
      prevSlide();
      e.preventDefault();
      return;
    case 36:    // e.DOM_VK_HOME:
    //case 38:    // e.DOM_VK_UP:
      firstSlide();
      e.preventDefault();
      return;
    case 35:    // e.DOM_VK_END:
      lastSlide();
      e.preventDefault();
      return;
    // The Logitech Presenter's F5/ESC button sometimes sends ESC,
    // sometimes F5. I can't figure out the rule, so treat them the same:
    case 27:     // e.DOM_VK_ESC:
    case 116:    // e.DOM_VK_F5:
      firstSlide();
      e.preventDefault();
      return;
  }
}

